package com.laowang.project.system.controller;

import java.util.Date;
import java.util.List;

import com.laowang.common.utils.SecurityUtils;
import com.laowang.project.system.domain.MyLifeCircleReply;
import com.laowang.project.system.domain.WxUser;
import com.laowang.project.system.service.MyLifeCircleReplyService;
import com.laowang.project.system.service.WxUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.laowang.framework.aspectj.lang.annotation.Log;
import com.laowang.framework.aspectj.lang.enums.BusinessType;

import org.springframework.web.bind.annotation.*;
import com.laowang.project.system.domain.MyLifeCircleComment;
import com.laowang.project.system.service.MyLifeCircleCommentService;
import com.laowang.framework.web.controller.BaseController;
import com.laowang.framework.web.domain.AjaxResult;
import com.laowang.common.utils.poi.ExcelUtil;
import com.laowang.framework.web.page.TableDataInfo;

/**
 * 生活圈评论Controller
 *
 * @author laowang
 * @date 2023-04-25
 */
@Api(tags = "生活圈评论回复接口")
@RestController
@RequestMapping("/lifeComment")
public class MyLifeCircleCommentController extends BaseController {
    @Autowired
    private MyLifeCircleCommentService myLifeCircleCommentService;

    @Autowired
    private MyLifeCircleReplyService myLifeCircleReplyService;



    @Autowired
    private WxUserService wxUserService;




    @ApiOperation(value = "小程序端 新增生活圈评论",notes = "")
    @PostMapping("/web/addLifeComment")
    public AjaxResult addLifeComment(@Validated @RequestBody MyLifeCircleComment myLifeCircleComment) {
        Integer mid = SecurityUtils.getLoginUser().getWxUser().getMid();
        myLifeCircleComment.setUserId(mid);
        Integer i = myLifeCircleCommentService.addLifeComment(myLifeCircleComment);
        //myLifeCircleCommentService.insertMyLifeCircleComment(myLifeCircleComment);

        return AjaxResult.success("操作成功",i);
    }

    @ApiOperation(value = "小程序端 新增生活圈回复",notes = "")
    @PostMapping("/web/addReply")
    public AjaxResult addLifeComment( @RequestBody MyLifeCircleReply myLifeCircleReply) {
        Integer mid = SecurityUtils.getLoginUser().getWxUser().getMid();
        myLifeCircleReply.setUserId(mid);
        WxUser wxUser = wxUserService.selectWxUserById(mid);
        myLifeCircleReply.setFromNickname(wxUser.getNickname());
        myLifeCircleReply.setFromAvatar(wxUser.getAvatar());
        WxUser wxUser1 = wxUserService.selectWxUserById(myLifeCircleReply.getToUserId());
        myLifeCircleReply.setToNickname(wxUser1.getNickname());
        myLifeCircleReply.setToAvatar(wxUser1.getAvatar());
        myLifeCircleReply.setCreateTime(new Date());
        myLifeCircleReplyService.insertMyLifeCircleReply(myLifeCircleReply);

        return AjaxResult.success("操作成功");
    }

    /**
     * 查询生活圈评论列表
     */
    @ApiOperation(value = "查询生活圈评论列表",notes = "")
    @PreAuthorize("@ss.hasPermi('system:lifeComment:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyLifeCircleComment myLifeCircleComment) {
        startPage();
        List<MyLifeCircleComment> list = myLifeCircleCommentService.selectMyLifeCircleCommentList(myLifeCircleComment);
        return getDataTable(list);
    }

    /**
     * 导出生活圈评论列表
     */
    @ApiOperation(value = "导出生活圈评论列表",notes = "")
    @PreAuthorize("@ss.hasPermi('system:lifeComment:export')")
    @GetMapping("/export")
    public AjaxResult export(MyLifeCircleComment myLifeCircleComment) {
        List<MyLifeCircleComment> list = myLifeCircleCommentService.selectMyLifeCircleCommentList(myLifeCircleComment);
        ExcelUtil<MyLifeCircleComment> util = new ExcelUtil<MyLifeCircleComment>(MyLifeCircleComment.class);
        return util.exportExcel(list, "lifeComment");
    }

    /**
     * 获取生活圈评论详细信息
     */
    @ApiOperation(value = "获取生活圈评论详细信息",notes = "")
    @PreAuthorize("@ss.hasPermi('system:lifeComment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(myLifeCircleCommentService.selectMyLifeCircleCommentById(id));
    }

    /**
     * 新增生活圈评论
     */
    @ApiOperation(value = "新增生活圈评论",notes = "")
    @PreAuthorize("@ss.hasPermi('system:lifeComment:add')")
    @PostMapping
    public AjaxResult add(@RequestBody MyLifeCircleComment myLifeCircleComment) {
        return toAjax(myLifeCircleCommentService.insertMyLifeCircleComment(myLifeCircleComment));
    }

    /**
     * 修改生活圈评论
     */
    @ApiOperation(value = "修改生活圈评论",notes = "")
    @PreAuthorize("@ss.hasPermi('system:lifeComment:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody MyLifeCircleComment myLifeCircleComment) {
        return toAjax(myLifeCircleCommentService.updateMyLifeCircleComment(myLifeCircleComment));
    }

    /**
     * 删除生活圈评论
     */
    @ApiOperation(value = "删除生活圈评论",notes = "")
    @PreAuthorize("@ss.hasPermi('system:lifeComment:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(myLifeCircleCommentService.deleteMyLifeCircleCommentByIds(ids));
    }
}
